<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="__ROOT__/Public/Admin/css/shortcut icon" href="favicon.ico">
    <link href="__ROOT__/Public/Admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/animate.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/default.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/js/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <script>
        var CC = {
            "PUBLIC":"__PUBLIC__",
            "ROOT":"__ROOT__",
            "APP":"__APP__",
        };
    </script>

    <style>
        .nav-tabs{
            margin-bottom: 20px;
        }
        .err-tip-color{
            color:#ed2a2a;
        }
        #content-main{height: calc(100%) !important;}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">

        <div class="col-sm-8 col-md-offset-2">

            <div class="ibox float-e-margins">
                <div class="ibox-content">

                    <form class="form-horizontal m-t js-ajax-forms" id="signupForm" action="{:U('Admin/Auth/edit')}" method="post" enctype="multipart/form-data">
                        <input type="hidden" name="ID" value="{$Authrule['ID']}">
                        <?php if($Authrule['ParentID']){ ?>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">父级</label>
                            <div class="col-sm-8">
                                <select class="form-control m-b" name="ParentID" required>
                                    {$select_categorys}
                                </select>
                            </div>
                        </div>
                        <?php }?>


                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称 *</label>
                            <div class="col-sm-8">
                                <input id="Title" name="Title" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error" value="{$Authrule['Title']}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">路由规则 *</label>
                            <div class="col-sm-8">
                                <input id="Name" name="Name" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error" value="{$Authrule['Name']}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">类型 *</label>
                            <div class="col-sm-8">
                                <select class="form-control m-b" id="Type" name="Type" aria-required="true" aria-invalid="true" class="error">
                                    <if condition="$Authrule['Type']=='admin_url'">
                                        <option value="admin_url">后台</option>
                                        <else />
                                        <option value="home_url">前台</option>
                                    </if>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit">保存</button>
                                <a class="btn btn-white" href="javascript:void(0);" onclick="self.location=document.referrer;">返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- 全局js -->
<script src="__ROOT__/Public/Admin/js/jquery.min.js?v=2.1.4"></script>
<script src="__ROOT__/Public/Admin/js/bootstrap.min.js?v=3.3.6"></script>
<script src="__ROOT__/Public/Admin/js/plugins/layer/layer.min.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript" src="__ROOT__/Public/Admin/js/ajaxForm.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/validate/jquery.validate.min.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/validate/messages_zh.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {

        $.validator.setDefaults({
            highlight: function (element) {
                $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
            },
            success: function (element) {
                element.closest('.form-group').removeClass('has-error').addClass('has-success');
            },
            errorElement: "span",
            errorPlacement: function (error, element) {
                if (element.is(":radio") || element.is(":checkbox")) {
                    error.appendTo(element.parent().parent().parent());
                } else {
                    error.appendTo(element.parent());
                }
            },
            errorClass: "help-block m-b-none",
            validClass: "help-block m-b-none "
        });
        var icon = "<i class='fa fa-times-circle'></i> ";
        var form = $('form.js-ajax-forms');
        var formloading = false;
        //表单验证开始
        form.validate({
            //验证规则
            rules: {
                Name: {
                    required: true
                },
                Title:{
                    required: true
                }
            },
            //验证未通过提示消息
            messages: {
                Name:{
                    required: icon + "请输入路由规则"
                },
                Title:{
                    required: icon + "请输入名称"
                }
            },
            //验证通过，提交表单
            submitHandler : function(forms) {
                if (formloading)
                    return;
                $(forms).ajaxSubmit({
                    url : form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
                    dataType : 'json',
                    beforeSubmit : function(arr, $form, options) {
                        formloading = true;
                    },
                    success : function(data, statusText, xhr, $form) {
                        formloading = false;
                        if (data.status) {
                            //添加成功
                            swal({
                                        title: "继续编辑？",
                                        text: "操作成功！",
                                        type: "success",
                                        showCancelButton: true,
                                        confirmButtonColor: "#DD6B55",
                                        confirmButtonText: "确认",
                                        cancelButtonText: "返回",
                                        closeOnConfirm: false,
                                        closeOnCancel: false
                                    },
                                    function (isConfirm) {
                                        if (isConfirm) {
                                            swal.close();
                                        } else {
                                            //swal("已取消", "您取消了删除操作！", "error");
                                            document.location.href = "{:U('Admin/Auth/index')}";
                                            return true;
                                        }
                                    });

                        } else {
                            swal("操作失败", data.info, "error");
                        }
                    }
                });
            }
        });

    });
</script>



</body>

</html>
